
import com.dinim.math.GeometryUtil;
import com.dinim.matrix.twodimensional.IPoint2D;
import com.dinim.matrix.twodimensional.Vector3;
import com.dinim.object.Line2D;
import com.dinim.object.Point2D;


public class VoronoiRegionLine implements VoronoiRegion {

    private IPoint2D point0, point1;
    
    public VoronoiRegionLine(IPoint2D point0, IPoint2D point1) {
        this.point0 = point0;
        this.point1 = point1;
    }

    public boolean contains(IPoint2D point) {
        Line2D line1 = new Line2D(point0, point1);
        Vector3 vec1 = line1.getNormal();
        IPoint2D regionPoint1 = new Point2D(point0.getX() + vec1.getX(), point0.getY() + vec1.getY());
        IPoint2D regionPoint2 = new Point2D(point1.getX() + vec1.getX(), point1.getY() + vec1.getY());
        Line2D regionLine1 = new Line2D(point0, regionPoint1);
        Line2D regionLine2 = new Line2D(point1, regionPoint2);
        Line2D regionLine3 = new Line2D(point0, point1);
        double cp1 = GeometryUtil.getCrossProduct(regionLine1.getP1(), regionLine1.getP2(), point);
        double cp2 = GeometryUtil.getCrossProduct(regionLine2.getP2(), regionLine2.getP1(), point);
        double cp3 = GeometryUtil.getCrossProduct(regionLine3.getP2(), regionLine3.getP1(), point);
        if((cp1 <= 0) && (cp2 <= 0) && (cp3 <= 0)){
            return true;
        }else{
            return false;
        }
    }
}
